package com.hualian.coupon.controller;

import com.hualian.coupon.exception.BusinessException;
import com.hualian.coupon.pojo.Admin;
import com.hualian.coupon.service.AdminService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Map;

/**
 * @author Lxd
 * @Description TODO
 * @date 2020/10/21 1:35
 * @Version 1.0
 */
@RestController("/admin")
public class AdminController {


    @Resource
    AdminService adminService;

    @PostMapping("/login")
    public Admin login(@RequestParam("phone") @Valid String phone,
                       @RequestParam("psw") @Valid String psw) {
        Admin admin = adminService.login(phone, psw);
        if (admin == null) {
            throw new BusinessException("账号密码错误");
        }
        return admin;
    }

    @GetMapping("/exit")
    public Map<String, Object> exit() {
        return null;
    }
}
